<?php

$html = '';
if ($list_customer_order) {


    if ($is_group_customer == 0) {
//sắp xếp theo ngày ORDER hoặc theo mã sp: không gom nhóm khách được
        $html_total_result = '';
        foreach ($list_customer_order as $customer_order) {
            $color_photo_name = $customer_order->product_color . "_" . $customer_order->product_code . "_" . $customer_order->manufacture;
            $color_photo_name = $core->convert_string_friendly($color_photo_name) . ".jpg";
            $path_color_photo = dirname(dirname(dirname(__FILE__))) . DS . "photo" . DS . "extra_photo" . DS . "thumb_extra_photo" . DS . $color_photo_name;

            if (file_exists($path_color_photo)) {
                $src_photo = 'photo/extra_photo/' . $color_photo_name;
                $src_photo_thumb = 'photo/extra_photo/thumb_extra_photo/' . $color_photo_name;
            } else {
                $src_photo = 'photo/' . $customer_order->main_photo;
                $src_photo_thumb = 'photo/thumb_photo/200_' . $customer_order->main_photo;
            }
            $var_count++;
            if ($customer_order->total_current_money > 0) {
                $excess_cash = number_format($customer_order->total_current_money / 1000);
                $debit = 0;
            } else {
                $excess_cash = 0;
                $debit = number_format($customer_order->total_current_money / 1000);
            }
            $html.='<tr class="tr_' . $customer_order->customer_order_id . '">';
            $html.='<td class="center" >' . $var_count . '</td>';
            $html.='<td class="center" >' . $customer_order->facebook_name . '
                <p></p>
                    <button  class="btn btn-primary print_address_customer" type="button" rel="'.$customer_order->customer_id.'" >Print address</button>
                </td>';

            $html.='<td class="center" >' . $customer_order->phone . '</td>';
            if ($customer_order->link_web == "") {
                $html.='<td class="center">' . $customer_order->product_code . '</td>';
            } else {
                $html.='<td class="center"><a href="' . $customer_order->link_web . '" target="_blank">' . $customer_order->product_code . '</a></td>';
            }


            $html.='<td class="center">' . $customer_order->product_size . '</td>
    <td class="center">' . $customer_order->product_num . '</td>
    <td class="center">' . $customer_order->product_color . '</td>
    <td class="center"><img rel="' . $src_photo . '" class="photo_product" src="' . $src_photo_thumb . '" width="100px"></td>
    <td class="center">
            <p></p>
               <b>';

            switch ($customer_order->order_status) {
                case 0: $html.= "Store";
                    break;
                case 1: $html.= "Online";
                    break;
                case 2: $html.= "Hàng có sẵn";
                    break;
                case 3: $html.= "Đã nhận hàng";
                    break;
                case 4: $html.= "Đang shipping";
                    break;
                case 5: $html.= "Khách đã nhận";
                    break;
                case 6: $html.= "Hết hàng";
                    break;
                case 7: $html.= "ORDER";
                    break;
                case 8: $html.= "Chưa chắc chắn";
                    break;
            }
            $html.=' </b>
                <p></p>
                             <button  class="btn btn-primary print_address_customer" type="button" rel="'. $customer_order->customer_id.'" >Print address</button>
                </td>
                <td class="center color_status">
                    <p class="description_product_detail" data-item-id="' . $customer_order->id . '">'.nl2br(htmlspecialchars($customer_order->description)).'</p>

                </td>';
            if($customer_order->order_status==6){
                $html.='<td class="center gp_3" id="td_price_' . $customer_order->id . '">0</td>';
            }else{
                $html.='<td class="center gp_3" id="td_price_' . $customer_order->id . '">' . number_format($customer_order->product_price / 1000) . '</td>';
            }

   


            $html.=' <td class="center gp_3" id="td_total_price_' . $customer_order->id . '">' . number_format($customer_order->product_num * $customer_order->product_price / 1000) . '</td>
    <td class="center gp_3" >' . number_format($customer_order->total_payment / 1000) . '</td>
    <td class="center gp_3" ></td>
    <td class="center gp_3" ></td>
    <td class="center" >' . $customer_order->order_description . '</td>
    <td class="center gp_4" >' . $customer_order->address . '</td>
    <td class="center gp_4" >';

            if ($customer_order->province == 1)
                $html.= "Ở tỉnh";
            else
                $html.= "Ở HN";

            $html.='</td>
    <td class="center gp_4" >' . $customer_order->name . '</td>
    <td class="center gp_4" >' . $customer_order->bank_account . '</td>
    <td class="center" >

    </td>
</tr>';
        }
    } else {
//gom theo khách
        $html_total_result = '';
        $customer_order_id = $last_customer_order_id;
        foreach ($list_customer_order as $customer_order) {
            $color_photo_name = $customer_order->product_color . "_" . $customer_order->product_code . "_" . $customer_order->manufacture;
            $color_photo_name = $core->convert_string_friendly($color_photo_name) . ".jpg";
            $path_color_photo = dirname(dirname(dirname(__FILE__))) . DS . "photo" . DS . "extra_photo" . DS . "thumb_extra_photo" . DS . $color_photo_name;

            if (file_exists($path_color_photo)) {
                $src_photo = 'photo/extra_photo/' . $color_photo_name;
                $src_photo_thumb = 'photo/extra_photo/thumb_extra_photo/' . $color_photo_name;
            } else {
                $src_photo = 'photo/' . $customer_order->main_photo;
                $src_photo_thumb = 'photo/thumb_photo/200_' . $customer_order->main_photo;
            }
            if ($customer_order_id != $customer_order->customer_order_id) {
                $var_count++;
                $customer_order_id = $customer_order->customer_order_id;
                if ($customer_order->total_current_money > 0) {
                    $excess_cash = number_format($customer_order->total_current_money / 1000);
                    $debit = 0;
                } else {
                    $excess_cash = 0;
                    $debit = number_format($customer_order->total_current_money / 1000);
                }
                $html.='<tr class="tr_' . $customer_order->customer_order_id . '">';
                $html.='<td class="center" rowspan="' . $customer_order->total_product . '">' . $var_count . '</td>';
                $html.='<td class="center" rowspan="' . $customer_order->total_product . '">';
                if ($customer_order->facebook_link != "") {
                    $html.='<a href="' . $customer_order->facebook_link . '" target="_blank">' . $customer_order->facebook_name . '</a>';
                } else {
                    $html.=$customer_order->facebook_name;
                }
                $html.='<p></p>
               <b>';

                switch ($customer_order->customer_order_status) {
                    case 0: $html.= "Store";
                        break;
                    case 1: $html.= "Online";
                        break;
                    case 2: $html.= "Hàng có sẵn";
                        break;
                    case 3: $html.= "Đã nhận hàng";
                        break;
                    case 4: $html.= "Đang shipping";
                        break;
                    case 5: $html.= "Khách đã nhận";
                        break;
                    case 6: $html.= "Hết hàng";
                        break;
                    case 7: $html.= "ORDER";
                        break;
                    case 8: $html.= "Chưa chắc chắn";
                        break;
                    case 9: $html.= "Chưa xác định";
                        break;
                }
                $html.=' </b>
                        <p></p>
                             <button  class="btn btn-primary print_address_customer" type="button" rel="'. $customer_order->customer_id.'" >Print address</button>
                        </td>
                        ';



                $html.='<td class="center" rowspan="' . $customer_order->total_product . '">' . $customer_order->phone . '</td>';
                if ($customer_order->link_web == "") {
                    $html.='<td class="center">' . $customer_order->product_code . '</td>';
                } else {
                    $html.='<td class="center"><a href="' . $customer_order->link_web . '" target="_blank">' . $customer_order->product_code . '</a></td>';
                }

                if($customer_order->customer_order_status==6){
                    $html.='<td class="center">0</td>';
                }else{
                    $html.='<td class="center">' . $customer_order->product_size . '</td>';
                }
                $html.='
    <td class="center">' . $customer_order->product_num . '</td>
    <td class="center">' . $customer_order->product_color . '</td>
    <td class="center"><img rel="' . $src_photo . '" class="photo_product" src="' . $src_photo_thumb . '" width="100px"></td>
    <td class="center">
         <b>';

                switch ($customer_order->order_status) {
                    case 0: $html.= "Store";
                        break;
                    case 1: $html.= "Online";
                        break;
                    case 2: $html.= "Hàng có sẵn";
                        break;
                    case 3: $html.= "Đã nhận hàng";
                        break;
                    case 4: $html.= "Đang shipping";
                        break;
                    case 5: $html.= "Khách đã nhận";
                        break;
                    case 6: $html.= "Hết hàng";
                        break;
                    case 7: $html.= "ORDER";
                        break;
                    case 8: $html.= "Chưa chắc chắn";
                        break;
                }
                $html.=' </b>
    </td>
    <td class="center color_status">
        <p class="description_product_detail" data-item-id="' . $customer_order->id . '">'.nl2br(htmlspecialchars($customer_order->description)).'</p>

    </td>';
                if($customer_order->order_status==6){
                    $html.=' <td class="center gp_3" id="td_price_' . $customer_order->id . '">0</td>';
                }else{
                    $html.=' <td class="center gp_3" id="td_price_' . $customer_order->id . '">' . number_format($customer_order->product_price / 1000) . '</td>';
                }
    


                $html.='<td class="center gp_3" id="td_total_price_' . $customer_order->customer_order_id . '" rowspan="' . $customer_order->total_product . '">' . number_format($customer_order->total_order_money / 1000) . '</td>
    <td class="center gp_3"  rowspan="' . $customer_order->total_product . '">' . number_format($customer_order->total_payment / 1000) . '</td>
    <td class="center gp_3" id="td_debit_' . $customer_order->customer_order_id . '" rowspan="' . $customer_order->total_product . '">' . $debit . '</td>
    <td class="center gp_3" id="td_excess_cash_' . $customer_order->customer_order_id . '" rowspan="' . $customer_order->total_product . '">' . $excess_cash . '</td>
     <td class="center" rowspan="' . $customer_order->total_product . '">' . $customer_order->order_description . '</td>
   
    <td class="center gp_4" rowspan="' . $customer_order->total_product . '">' . $customer_order->address . '</td>
    <td class="center gp_4" rowspan="' . $customer_order->total_product . '">';

                if ($customer_order->province == 1)
                    $html.= "Ở tỉnh";
                else
                    $html.= "Ở HN";

                $html.='</td>
    <td class="center gp_4" rowspan="' . $customer_order->total_product . '">' . $customer_order->name . '</td>
    <td class="center gp_4" rowspan="' . $customer_order->total_product . '">' . $customer_order->bank_account . '</td>
    <td class="center" rowspan="' . $customer_order->total_product . '">
        
    </td>
</tr>';
            } else {

                $html.=' <tr class="tr_' . $customer_order->customer_order_id . '">';
                if ($customer_order->link_web == "") {
                    $html.='<td class="center">' . $customer_order->product_code . '</td>';
                } else {
                    $html.='<td class="center"><a href="' . $customer_order->link_web . '" target="_blank">' . $customer_order->product_code . '</a></td>';
                }


                $html.='<td class="center">' . $customer_order->product_size . '</td>
    <td class="center">' . $customer_order->product_num . '</td>
    <td class="center">' . $customer_order->product_color . '</td>
    <td class="center"><img rel="' . $src_photo . '" class="photo_product" src="' . $src_photo_thumb . '" width="100px"></td>
    <td class="center">
         <b>';

                switch ($customer_order->order_status) {
                    case 0: $html.= "Store";
                        break;
                    case 1: $html.= "Online";
                        break;
                    case 2: $html.= "Hàng có sẵn";
                        break;
                    case 3: $html.= "Đã nhận hàng";
                        break;
                    case 4: $html.= "Đang shipping";
                        break;
                    case 5: $html.= "Khách đã nhận";
                        break;
                    case 6: $html.= "Hết hàng";
                        break;
                    case 7: $html.= "ORDER";
                        break;
                    case 8: $html.= "Chưa chắc chắn";
                        break;
                }
                $html.=' </b>
    </td>
    <td class="center color_status">
        <p class="description_product_detail" data-item-id="' . $customer_order->id . '">'.nl2br(htmlspecialchars($customer_order->description)).'</p>

    </td>
    
    <td class="center gp_3" id="td_price_' . $customer_order->id . '">' . number_format($customer_order->product_price / 1000) . '</td>';

                $html.='</tr>';
            }
        }
    }
}
?>